home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11207 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  51 lines

  1. Newsgroups: comp.lang.c
  2. Path: sword.eng.pyramid.com!pyrltd!markb
  3. From: markb@pyramid.com (Mark Bluemel)
  4. Subject: Re: operator % - compiler error
  5. Message-ID: <1996Mar22.142327.17591@pyra.co.uk>
  6. Sender: news@pyra.co.uk
  7. Organization: Pyramid Technology Ltd.
  8. X-Newsreader: TIN [version 1.2 PL2]
  9. References: <4ihuuh$6ul@hatathli.csulb.edu> <DoH503.Hu7@iquest.net>
  10. Date: Fri, 22 Mar 1996 14:23:27 GMT
  11.  
  12. Doug Miller (dlmiller@iquest.net) wrote:
  13. : davidcho@csulb.edu (David Cho) wrote:
  14.  
  15. [Complete headers of quoted posting snipped...]
  16.  
  17. : +When I try to compile, I get an erro message for the following line:
  18. : +
  19. : +
  20. : +x=663608941*y%pow(2,32)  /*I want remainder*/
  21. : +
  22. : +But the error message says "illegal use of floating point".  What does
  23. : +that mean?  Isn't % used a an operator to calcuate the remainder?
  24.  
  25. : You're right that % is the modulo operator.
  26.  
  27. [Next block of text reformatted to < 78 characters per line]
  28. : Hard to say for sure what caused the error, as you have not posted the 
  29. : declarations of x and y.  But here are some suggestions. Remember that * is 
  30. : the indirection operator, as well as the multiplication operator; try 
  31. : putting spaces before and after the * so the compiler knows what you mean.
  32. : Do the same with the % operator.  And remember you need a semicolon at the 
  33. : end of your statement.
  34.  
  35. I disagree with all the reply Doug gave, except perhaps his comment about the
  36. semicolon. The problem is almost certainly that % gives the remainder after
  37. *integer* division, and expects both operands to be integers.... pow() takes
  38. *doubles* as arguments and returns a *double*.
  39.  
  40. As Doug says, we don't know what x and y are declared as - presumably doubles
  41. as AFAIK y%pow(2,32) wouldn't give anything useful with normal integer
  42. datatypes (assuming an implementation limit of 32 bits for integers). I'm
  43. afraid that % isn't usable here - could David post more details of what he's
  44. trying to achieve?
  45.  
  46. --
  47. Mark Bluemel    Unix/Oracle Trainer and Consultant
  48.         My opinions are my own, but I'll share them
  49.         All solutions to problems are offered "as is"
  50.         and without warranty - you have been warned :-)
  51.